package com.ruoyi.product.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.product.domain.ProductWelding;
import com.ruoyi.product.service.IProductWeldingService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊缝管理Controller
 * 
 * @author ruoyi
 * @date 2022-12-12
 */
@Controller
@RequestMapping("/product/welding")
public class ProductWeldingController extends BaseController
{
    private String prefix = "product/welding";

    @Autowired
    private IProductWeldingService productWeldingService;

    @RequiresPermissions("product:welding:view")
    @GetMapping()
    public String welding()
    {
        return prefix + "/welding";
    }

    /**
     * 查询焊缝管理列表
     */
    @RequiresPermissions("product:welding:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ProductWelding productWelding)
    {
        startPage();
        List<ProductWelding> list = productWeldingService.selectProductWeldingList(productWelding);
        return getDataTable(list);
    }

    /**
     * 导出焊缝管理列表
     */
    @RequiresPermissions("product:welding:export")
    @Log(title = "焊缝管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ProductWelding productWelding)
    {
        List<ProductWelding> list = productWeldingService.selectProductWeldingList(productWelding);
        ExcelUtil<ProductWelding> util = new ExcelUtil<ProductWelding>(ProductWelding.class);
        return util.exportExcel(list, "焊缝管理数据");
    }

    /**
     * 新增焊缝管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊缝管理
     */
    @RequiresPermissions("product:welding:add")
    @Log(title = "焊缝管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ProductWelding productWelding)
    {
        return toAjax(productWeldingService.insertProductWelding(productWelding));
    }

    /**
     * 修改焊缝管理
     */
    @RequiresPermissions("product:welding:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ProductWelding productWelding = productWeldingService.selectProductWeldingById(id);
        mmap.put("productWelding", productWelding);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊缝管理
     */
    @RequiresPermissions("product:welding:edit")
    @Log(title = "焊缝管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ProductWelding productWelding)
    {
        return toAjax(productWeldingService.updateProductWelding(productWelding));
    }

    /**
     * 删除焊缝管理
     */
    @RequiresPermissions("product:welding:remove")
    @Log(title = "焊缝管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(productWeldingService.deleteProductWeldingByIds(ids));
    }
}
